package com.java.module.chat.controller.admin;

import java.util.List;

import com.java.module.chat.domain.ChatGroup;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.java.common.lang.annotation.Log;
import com.java.common.lang.domain.AjaxResult;
import com.java.common.lang.enums.BusinessTypeEnum;
import com.java.common.utils.WebKit;
import com.java.module.chat.service.IChatGroupService;
import com.java.common.utils.poi.ExcelUtil;
import com.java.common.lang.domain.page.TableDataInfo;

/**
 * 聊天模块：群聊Controller
 * 
 * @author Administrator
 * @date 2023-02-16
 */
@RestController("AdminChatGroupController")
@RequestMapping("/chat/chatGroup")
public class ChatGroupController
{
    @Autowired
    private IChatGroupService chatGroupService;

    /**
     * 查询聊天模块：群聊列表
     */
    @PreAuthorize("@ss.hasPermi('chat:chatGroup:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChatGroup chatGroup)
    {
        WebKit.startPage();
        List<ChatGroup> list = chatGroupService.selectChatGroupList(chatGroup);
        return WebKit.getDataTable(list);
    }

    /**
     * 导出聊天模块：群聊列表
     */
    @PreAuthorize("@ss.hasPermi('chat:chatGroup:export')")
    @Log(title = "聊天模块：群聊", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ChatGroup chatGroup)
    {
        List<ChatGroup> list = chatGroupService.selectChatGroupList(chatGroup);
        ExcelUtil<ChatGroup> util = new ExcelUtil<ChatGroup>(ChatGroup.class);
        return util.exportExcel(list, "chatGroup");
    }

    /**
     * 获取聊天模块：群聊详细信息
     */
    @PreAuthorize("@ss.hasPermi('chat:chatGroup:query')")
    @GetMapping(value = "/{groupId}")
    public AjaxResult getInfo(@PathVariable("groupId") Long groupId)
    {
        return AjaxResult.success(chatGroupService.selectChatGroupById(groupId));
    }

    /**
     * 新增聊天模块：群聊
     */
    @PreAuthorize("@ss.hasPermi('chat:chatGroup:add')")
    @Log(title = "聊天模块：群聊", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChatGroup chatGroup)
    {
        return WebKit.toAjax(chatGroupService.insertChatGroup(chatGroup));
    }

    /**
     * 修改聊天模块：群聊
     */
    @PreAuthorize("@ss.hasPermi('chat:chatGroup:edit')")
    @Log(title = "聊天模块：群聊", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChatGroup chatGroup)
    {
        return WebKit.toAjax(chatGroupService.updateChatGroup(chatGroup));
    }

    /**
     * 删除聊天模块：群聊
     */
    @PreAuthorize("@ss.hasPermi('chat:chatGroup:remove')")
    @Log(title = "聊天模块：群聊", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{groupIds}")
    public AjaxResult remove(@PathVariable Long[] groupIds)
    {
        return WebKit.toAjax(chatGroupService.deleteChatGroupByIds(groupIds));
    }
}
